<?php
/**
 * 功能：
 * 说明：
 * 创建日期：
 * 更新日期：
 * 作者：Mirze
 * 补充说明： 
 * 
 */
class Model 
{	
    protected $db = null;	// 当前数据库操作对象   
    protected $pk  = 'id';	 // 主键名称	
    protected $tablePrefix  =   '';	// 数据表前缀    
    protected $name = '';	// 模型名称    
    protected $dbName  = '';	// 数据库名称    
    protected $tableName = ''; // 数据表名（不包含表前缀）    
    protected $trueTableName =''; // 实际数据表名（包含表前缀）
	protected $_dsn  = array();	 //数据库配置	

	const TABLE_PREFIX = 'm_'; //默认表前缀

	 public function __construct($name='',$tablePrefix='',$connection='') {
		 if(! is_resource($this->db)) {
			 $this->getCon();
		 }

		 // 设置表前缀
        if(is_null($tablePrefix)) {// 前缀为Null表示没有前缀
            $this->tablePrefix = '';
        }elseif('' != $tablePrefix) {
            $this->tablePrefix = $tablePrefix;
        }else{
            $this->tablePrefix = $this->tablePrefix ? $this->tablePrefix : self::TABLE_PREFIX;
        }
	 }

	 /**  **/
	 function getConf()
	 {
		$dsn['host'] = 'localhost';
		$dsn['port'] = '3306';
		$dsn['login'] = 'root';
		$dsn['password'] = '123456';
		$dsn['driver']   = 'mysql';
		$dsn['database'] = 'thinkphp';

		$this->_dsn = $dsn;
		 return $dsn;
	 }

	 /**  **/
	 function getCon()
	 {
		 $conf = $this->getConf();
		 $this->db = DB::getConn($conf);
		 if(! is_resource($this->db)) {
			 exit('db connect fail');
		 }		 
	 }

	 /**  **/
	 function getDbName()
	 {
		$this->dbName = $this->_dsn['database'];
	 }

	/** 得到完整的数据表名 **/
	public function getTableName() 
	{
        if(empty($this->trueTableName)) {
            $tableName  = !empty($this->tablePrefix) ? $this->tablePrefix : '';
            if(!empty($this->tableName)) {
                $tableName .= $this->tableName;
            }else{
                $tableName .= parse_name($this->name);
            }
            $this->trueTableName = strtolower($tableName);
        }
        return (!empty($this->dbName) ? $this->dbName . '.' : '').$this->trueTableName;
    }

	/**
	 * (功能描述)
	 *
	 * @param 
	 * @return
	 */
	public function add($data='',$options=array())
	{
		
	}

	/**
	 * (功能描述)
	 *
	 * @param 
	 * @return
	 */
	public function save($data='',$options=array())
	{
		
	}


}

?>